define(function (require, exports, module) {
    var Validator = require("./common/validator.js");
    require("./common/dialog");

    var FormValidator = {
        editValidator: function (element) {
            var v = new Validator({
                attrs: {itemClass: "test"},
                element: element,
                autoSubmit: false,
                onFormValidated: function (err, results, form) {
                    if (!err) {
                        $.ajax({
                            url: window.jkconfig.webapiurlv + "editPassword",
                            type: 'POST',
                            data: $("#editForm").serialize(),
                            success: function (data) {
                                if (data.code == 0) {
                                    if (data.msg == "密码输入有误") {
                                        $.showErr("修改失败！");
                                    } else {
                                        $.showSuccessTimeout("修改成功!", function () {
                                            parent.location.href = 'login.html';
                                        });
                                    }
                                }
                            }
                        });
                    }
                    return false;
                },
                failSilently: true
            });
            v.addItem({
                element: '[name=oldPwd]',
                required: true,
                display: '旧密码',
                rule: 'numberOrLetter'
            }).addItem({
                element: '[name=newPwd]',
                required: true,
                display: '新密码',
                rule: 'numberOrLetter'
            });
        }
    }
    module.exports = FormValidator;
});